#include "cursorposcalculator.h"
#include <QRect>

uint CursorPosCalculator::borderWidth = 5;
uint CursorPosCalculator::titleHeight = 30;

CursorPosCalculator::CursorPosCalculator()
{
    reset();
}

void CursorPosCalculator::reset()
{
    isOnEdges = false;
    isOnLeftEdge = false;
    isOnRightEdge = false;
    isOnTopEdge = false;
    isOnBottomEdge = false;
    isOnTopLeftEdge = false;
    isOnBottomLeftEdge = false;
    isOnTopRightEdge  = false;
    isOnBottomRightEdge = false;
}

void CursorPosCalculator::recalculate(const QPoint &gMousePos, const QRect &frameRect)
{
    int globalMouseX = gMousePos.x();
    int globalMouseY = gMousePos.y();

    int frameX = frameRect.x();
    int frameY = frameRect.y();

    int frameWidth = frameRect.width();
    int frameHeight = frameRect.height();

    isOnLeftEdge = (globalMouseX >= frameX &&
                  globalMouseX <= frameX + borderWidth );


    isOnRightEdge = (globalMouseX >= frameX + frameWidth - borderWidth &&
                   globalMouseX <= frameX + frameWidth);

    isOnTopEdge = (globalMouseY >= frameY &&
                 globalMouseY <= frameY + borderWidth );

    isOnBottomEdge = (globalMouseY >= frameY + frameHeight - borderWidth &&
                    globalMouseY <= frameY + frameHeight);

    isOnTopLeftEdge = isOnTopEdge && isOnLeftEdge;
    isOnBottomLeftEdge = isOnBottomEdge && isOnLeftEdge;
    isOnTopRightEdge = isOnTopEdge && isOnRightEdge;
    isOnBottomRightEdge = isOnBottomEdge && isOnRightEdge;

    isOnEdges = isOnLeftEdge || isOnRightEdge || isOnTopEdge || isOnBottomEdge;
}

